#pragma once

using namespace Ogre;
#include <OIS/OIS.h>

class GameAppInputHandler;
class OIS::KeyEvent;
class GameAppListener : public FrameListener, public WindowEventListener, public OIS::KeyListener
{
	friend class GameAppInputHandler;
public:
						GameAppListener(RenderWindow* window);
	virtual				~GameAppListener();

public:
	void					windowResize(RenderWindow* window);
	void					windowClosed(RenderWindow* window);

	bool					frameRenderingQueued(const FrameEvent& evt);
	bool					frameEnded(const FrameEvent& evt);

	void					switchDebugOverlay();
	
	void					ExitApp()					{ m_IsExitApp = true;}

	virtual bool keyPressed( const OIS::KeyEvent &arg );
	virtual bool keyReleased( const OIS::KeyEvent &arg ){ return true;}

public:
	OIS::InputManager*		GetInputManager()			{ return m_InputManager; }
	OIS::Keyboard*			GetKeyboard()				{ return m_Keyboard; }
	OIS::Mouse*				GetMouse()					{ return m_Mouse; }
	GameAppInputHandler*	GetInputHandler()			{ return m_InputHandler; }

private:
	void					MoveCamera();
	void					UpdateInputVariable();

protected:
	virtual void			debugState();

private:
	float					m_beforeTime;

private:
	RenderWindow*			m_Window;
	OIS::InputManager*		m_InputManager;
	OIS::Keyboard*			m_Keyboard;
	OIS::Mouse*				m_Mouse;
	bool					m_IsExitApp;

	bool					m_IsKeyboardInput;
	bool					m_IsMouseInput;

private:
	Vector3					m_TranslateVector;
	Vector3					m_camMoved;
	Radian					m_camRotX;
	Radian					m_camRotY;

	float					m_MoveScale;
	float					m_MoveSpeed;
	float					m_CurrentSpeed;
	float					m_SpeedLimit;
	bool					m_UpdateMovement;
	
	bool					m_MoveLeft;
	bool					m_MoveRight;
	bool					m_MoveFwd;
	bool					m_MoveBck;

	bool					m_RotateCam;
	int						m_RotateAxisX;
	int						m_RotateAxisY;

private:
	Overlay*				m_DebugOverlay;
	std::string				m_DebugText;
	bool					m_EnabledDebugState;

private:
	GameAppInputHandler*	m_InputHandler;
};

class GameAppInputHandler : public IEventHandler
{
public:
	GameAppInputHandler(GameAppListener* listener) 
		:appListener(listener) {}

	virtual bool IsEnabled() { return true;	}
	virtual void OnEvent(Event* evt);

private:
	GameAppListener*		appListener;
};

